package com.mmy.dao.bidtender;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.bidtender.TBidTrip;

public interface TBidTripRepository extends JpaRepository<TBidTrip, Integer> {
	/**
	 * 获得最大编号
	 * 
	 * @return 返回值说明 最大ID
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.12.10
	 */
	@Query(value = "select MAX(iTripID)  from tBidTrip where LEFT(iTripID,2) = RIGHT(YEAR(NOW()),2)", nativeQuery = true)
	Object getMaxTripID();

	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tBidTrip(iTripID, iTenderID, iDay, cAddress, cStay, cMeal, cTrip, cHotelPath1, cHotelPath2, cHotelPath3, cHotelPath4, cScenicPath1, cScenicPath2, cScenicPath3, cScenicPath4, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (?1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(int tripID);

	/**
	 * 前台个人中心通过投标ID查询投标行程信息
	 *
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.10.29
	 */
	@Query(value = "select *  from tBidTrip where iTenderID=?1 order by iDay", nativeQuery = true)
	List<TBidTrip> findByTenderID(int iTenderID);

	/**
	 * 前台修改投标行程时用到
	 *
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.12.14
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tBidTrip where iTenderID =?1", nativeQuery = true)
	void deleteByTenderID(int iTenderID);

	/* 未用到2020.12.16 */
	@Transactional
	@Modifying
	@Query(value = "delete from tBidTrip where iTenderID in(:iTenderIDs)", nativeQuery = true)
	void deleteChecked(@Param("iTenderIDs") List<Integer> iTenderIDs);

}
